class Solution:
    def maxSubArray(self, nums: List[int]) -> int:
        sums = 0
        res = nums[0]
        for i in nums:
            if sums > 0:
                sums += i
            else:
                sums = i
            res = max(res,sums)
        return res
'''
res 起点是第一个数,否则就一个数且小于0 的情况会出差错
如果sums大于零继续+,小于0,sums直接从头开始(相当于等于零但是少了一个判断)
'''
class Solution(object):
    def maxSubArray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
         """
        for i in range(1, len(nums)):
            nums[i]= nums[i] + max(nums[i-1], 0)
        return max(nums)